<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>js类之基础严格模式</title>
</head>
<body>
  <ul>
    <li>使用class定义的嵌套方法内部this默认返回undefined，相当于自动适配"严格模式"</li>
    <li>在"严格模式"下，使用function定义的嵌套方法内部this返回undefined, 非严格模式下返回window</li>
  </ul>
  <script>
    'use strict'
    console.log('****************用class定义类****************')
    {
      class User {
        show() {
          function detail() {
            console.log(this)       // undefined
          }
          detail()
        }
      }
      const user = new User()
      user.show()
    }
    console.log('****************用funtion定义类****************')
    {
      function User() {}
      User.prototype.show = function () {
        function detail() {
          console.log(this)       // undefined
        }
        detail()
      }
      const user = new User()
      user.show()
    }
  </script>
</body>
</html>